﻿using System;
using Jayden.Dll.Core.Extensions;
using Jayden.Dll.Web.Enums;
using Jayden.Dll.Web.HtmlControls.Descriptions;
using Jayden.Dll.Web.HtmlControls.Generics;
using Jayden.Dll.Web.HtmlControls.Interfaces;

namespace Jayden.Dll.Web.HtmlControls
{
	public class Button : HtmlElement, WithName, WithDisabled, WithForm, WithValue
	{
		public Button() : base(ButtonDescription.Instance) { }

		public string Name { get { return this["name"]; } set { this["name"] = value; } }
		public string Value { get { return this["value"]; } set { this["value"] = value; } }
		public HtmlButtonType Type { get { return (HtmlButtonType)Enum.Parse(typeof(HtmlButtonType), GetAttribute("type", false, false, "submit").CamelCase(), true); } set { this["type"] = (value == HtmlButtonType.Submit) ? null : value.ToString().UnCamelCase(); } }
		public bool Disabled { get { return GetAttributeBool("disabled"); } set { SetAttribute("disabled", value); } }
		public bool Enabled { get { return !Disabled; } set { Disabled = !value; } }
		public string Form { get { return this["form"]; } set { this["form"] = value; } }
	}
	public class ButtonDescription : HtmlElementDescription
	{
		public static readonly ButtonDescription Instance = new ButtonDescription();
		private ButtonDescription() : base("button") { }
		public override Type ControlType { get { return typeof(Button); } }
		public override string Description { get { return "multipurpose element for representing buttons."; } }
		public override bool OnlyPhrasingContent { get { return true; } }
		public override bool IsPhrasingElement { get { return true; } }
	}
}
